﻿using System;
using CannedHeater.ViewModel;
using Microsoft.Phone.Controls;

namespace CannedHeater
{
    /// <summary>
    /// The page for modifying settings of the app
    /// </summary>
    public partial class SettingsPage : PhoneApplicationPage
    {
        // Set the datacontext of the SettingsView
        private SettingsViewModel vm = new SettingsViewModel();
        public SettingsPage()
        {
            InitializeComponent();
            SettingsView.DataContext = vm;
        }

        #region Tombstoning
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            vm.LoadTombstone(State);
        }

        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            base.OnNavigatingFrom(e);
            vm.Tombstone(State);
        }
        #endregion

        private void CancelBtn_Click(object sender, EventArgs e)
        {
            vm.Cancel();
            NavigationService.GoBack();
        }

        private void SaveBtn_Click(object sender, EventArgs e)
        {
            vm.SaveSettings();
        }
    }
}